package com.Maykk.objSerialization;

import java.io.*;

/**
 * @ClassName: Demo02
 * @Description: TODO 对象序列化和反序列化
 * @Author: MaykkStar@163.com
 */
public class Demo02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student student = new Student("早期的鸟儿", "男", 18, 100);
        // 将对象序列化存储进文件
        // ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Maykk.txt"));
        // oos.writeObject(student);
        // oos.close();

        // 从文件中读取对象（反序列化）
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("./Maykk.txt"));
        Student stuNew = (Student) ois.readObject();
        ois.close();
        System.out.println(stuNew);
        System.out.println(stuNew.getName());
        System.out.println(stuNew.getAge());

    }
}
